<template>
<div>
  <a-button type="primary" @click="closeWeiLan">隐藏围栏</a-button>||
  <a-button type="primary" @click="weiLan">显示围栏</a-button>

  <div id="map">
    <div id="popup" class="ol-popup">
      <div id="popup-content" class="popup-content"></div>
    </div>
  </div>
</div>
</template>

<script>
import "ol/ol.css";
import {
  olMap
} from "../../../utils/map.js";
const URL = require("../JSON/5.json");
export default {
  data() {
    return {
      map: null,
      personIcon: [{
          x: 27.970491535012,
          y: 6871.263035307627,
          type: "p1.png",
        },
        {
          x: 485.5882702715971,
          y: 1269.2510749397316,
          type: "p1.png",
        },
        {
          x: 18.7480305399586,
          y: 10292.284252992747,
          type: "p1.png",
        },
      ],
      Icon: [{
          x: 2827.970491535012,
          y: 6871.263035307627,
          type: "1.png",
        },
        {
          x: 985.5882702715971,
          y: 3669.2510749397316,
          type: "2.png",
        },
        {
          x: 1618.7480305399586,
          y: 10292.284252992747,
          type: "p.png",
        },
      ],
      // 围栏数据
      // 围栏图层数据
      weilan: [{
        type: "Feature",
        properties: {
          name: "围栏一",
        },
        geometry: {
          type: "Polygon",
          coordinates: [
            [
              [-3827.970491535012, 36871.263035307627],
              [10384.970491535012, 36871.263035307627],
              [10384.970491535012, 71.263035307627],
              [-3827.970491535012, 71.263035307627],
              [-3827.970491535012, 36871.263035307627],
            ],
          ],
        },
      }, ],
    };
  },
  mounted() {
    this.init();
    //小人移动事件
  },
  methods: {
    init() {
      this.map = new olMap();
      // 加载底图
      this.map.init(URL);
      //  加载小人
      // 增加点击事件
      // this.map.pointermove("click");
      // 显示围栏
      this.weiLan();
      this.map.addHUiHua();
      this.map.addInteraction({
        stroke: "#fcf",
        fill: "rgba(0,255,255,0.3)",
      });
    },
    //关闭围栏
    closeWeiLan() {
      this.map.removeWeiLan();
    },
    // 显示围栏
    weiLan() {
      // 增加围栏
      this.map.addWeiLan(this.weilan, {
        stroke: "#fcf",
        fill: "rgba(0,255,255,0.3)",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
#map {
  width: 1000px;
  height: 600px;
}

.popup-content {
  width: 100px;
  height: 40px;
  background-color: rgb(211, 230, 230);
  font-size: 16px;
  text-align: center;
  line-height: 40px;
}
</style>
